package org.vectrics.recruiter.struts.tag;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import org.apache.ecs.html.A;
import org.vectrics.common.html.BorderTable;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;
import org.vectrics.common.html.Table;
import org.vectrics.common.html.TextHelper;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.job.JobCandidate;
import org.vectrics.recruiter.job.JobCandidateCriteria;
import org.vectrics.user.Person;

/**
 * @author mmoore
 */
public class ApplicantsTag extends JobCandidateListTag {
	public static final long serialVersionUID = 78924620345364514L;
    private String observerId = null;

    
	protected String getDescription() {
	    return(null);
	}
	
    protected String getPageListLink() {
   		return(getContextPath() + "/admin/user/applicants.do");
    }
		
	protected JobCandidateCriteria createCriteria() {
	    JobCandidateCriteria criteria = super.createCriteria();
	    
	    Collection statuses = new HashSet();
	    statuses.add("cand-appl");
	    criteria.setStatusSet(statuses);
	    if (observerId != null) {
	        Person observer = this.getAuthPerson();
	        criteria.setObserver(observer);
	    }
	    return(criteria);
	}

	protected void showList(String str,	Cell listCell, List jobCandidates) {
	    Table mainTable = new BorderTable();
	    mainTable.setWidth("100%");
	    listCell.addElement(mainTable);
	    
	    Row headerRow = mainTable.addRow();
        headerRow.setDefaultBgImage(this.getContextPath() + "/site-graphics/tbl_hdr.gif");
        
	    Cell hdrDateCell = headerRow.addCell();
        //hdrDateCell.setClass("tableHdrBg");
	    hdrDateCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("phrase.job.candidate.date")));
	    Cell hdrPersonCell = headerRow.addCell();
        //hdrPersonCell.setClass("tableHdrBg");
	    hdrPersonCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("phrase.job.candidate.person.name")));
	    Cell hdrJobCell = headerRow.addCell();
        //hdrJobCell.setClass("tableHdrBg");
	    hdrJobCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("phrase.job.name")));
	    Cell hdrActionsCell = headerRow.addCell();
        //hdrActionsCell.setClass("tableHdrBg");
	    
	    Iterator iter = jobCandidates.iterator();
	    if (iter.hasNext()) {
		    while (iter.hasNext()) {
		        JobCandidate jobCandidate = (JobCandidate)iter.next();
		        
		        Row row = mainTable.addRow();
		        Cell dateCell = row.addCell();
		        dateCell.addElement(TextHelper.getFont("subFont", 
		        		CoreServiceLocator.getDateFormat().getDateFormatRoundToMinute(this.getLocale()).format(jobCandidate.getDateAdded())));
		        Cell personCell = row.addCell();
		        personCell.addElement(TextHelper.getFont("subFont", jobCandidate.getCandidate().getPerson().getName()));
		        Cell jobCell = row.addCell();
		        jobCell.addElement(TextHelper.getFont("subFont", jobCandidate.getJob().getTitle()));
		        Cell actionCell = row.addCell();
		        A link = new A();
		        link.setClass("subLink");
		        link.addElement(this.getPhrase("phrase.view"));
		        link.setHref(this.getContextPath() + "/admin/jobs/candidate/view/index.do?jobId=" 
		        		+ jobCandidate.getJob().getId() 
		                + "&userId=" + jobCandidate.getCandidate().getPerson().getId() + "&jobCandidateId=" 
						+ jobCandidate.getId());
		        actionCell.addElement(link);
		    }
	    } else {
	        // No elements
	        Row row = mainTable.addRow();
	        Cell cell = row.addCell();
	        cell.setColSpan(headerRow.getColumnCount());
	        cell.addElement(TextHelper.getFont("subFont", "<i>" + this.getNoElementsMessage() + "</i>"));
	    }
	    
	    
	    
	}
   
}
